import formJs from "./regexDetail.js"; //新增弹框配置项
import myCharts from "@/components/intelligentMaintenanceManage/temperatureHumidity/echarts.vue";
import TableData from "@/components/public/el-table"; //主页面列表
//主页面列表
import publicForm from "@/components/materialDataManage/fromCom.vue"; //弹框form
import actions from "@/actions";
import FormLyout from '@/components/commonPublic/fromLayout.vue'

import {
    getWs08HygsMonitordataByFid, //详情
    getWs08HygsMonitordataByFids,
} from "@/api/request.js";
export default {
 
    data() {
        return {
            visible: "",
            loadings: false,
            title: null,
            isLock: false,
            loading: false,
            tableData: [],
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            queryCriteriaData: {}, //分页

            dialogHeight: null,
            activeIndex: "1",
            formObj: formJs.formObj,
            additionalObj: formJs.additionalObj,
            isEdit: false,
            currntData: null,
            dataInfo: null,
            startDates: null,
            treeData: [], //材料种类
            getList: {
                taskNumber: "", //该数据的设备编号(必传)
                startDates: "", //开始时间(必传) 精确到秒  一般传当前时间的前40分钟
                endDates: "", //结束时间(必传）一般传当前时间的前40分钟
                page: 1, //当前页码
                pageSize: 15, //每页显示条数
                timeDates: null
            },
            formData: {
                fId: "", //必传
                userId: "", //当前登录人id
                userName: "", //当前登录人姓名
                recordfiles: [], //删除文件id集合
                fCommissiondates: this.common.day(0), //委托日期
                fCommissionname: "", //委托人
                fCommissionid: "", //委托人id
                fUnitname: "", //接收委托单位名称
                fUnitid: "", //接收委托单位id
                fOrdernumber: "", //委托单号
                fFileurl: "", //委托单附件
                fNote: "" //备注
            },
            formDatafileList: [], //工作计划资料
            btnShow: true,
            currentDetail: null,
            selectPostionObj: [],
            types: [],
            // 材料弹框
            materialRow: {},
            typeData: [{
                    text: "实时数据",
                    show: true
                },
                {
                    text: "列表数据",
                    show: false
                },
            ],
            chartsData: null,
            fCompanynames: null,
            fCompanyids: null,
            fFileurllist: [], //附件
            primaryInfo:null,
            flag:0
        };
    },
    components: {
        publicForm,
        myCharts,
        TableData,
        FormLyout

    },
   
   
    mounted() {
        this.primaryInfo = JSON.parse(sessionStorage.getItem("GxEmbedded_primaryInfo"))
        this.flag=1;
        var that=this;
        setTimeout(()=>{
            that.flag=1;
        },500)
        console.log(0,this.primaryInfo);
        actions.onGlobalStateChange((state, prev) => {
            var data = prev.currentUser.projects;
            this.userInfo = prev.currentUser
        }, true);
        this.currentDetail = this.primaryInfo.data;
        // if (this.statusNum != 1) {
        this.getList.taskNumber = this.primaryInfo.data.fDeviceencode
        this.getList.startDates = this.common.day(0) + " " + "00:00:00"
        this.getList.endDates = this.common.day(0) + " " + "23:59:59"
        this.getList.timeDates = this.common.day(0)

        this.getDetail(this.getList)
        this.getDetail1(this.getList)
        this.btnShow = true
        if (this.primaryInfo.status == 7) { //查看
            this.btnShow = false
           
            this.formData.fId = this.primaryInfo.data.fId//按钮 
            this.getDetail({
                fId: this.primaryInfo.data.fId
            })
            // this.formObj[6].uploadSelect = false
        }
     
    },
    methods: {
        timeFormat(minute) {
            //60000毫秒 代表1分钟
            let state = new Date(new Date().getTime() - minute * 60000);
            let date = new Date(state);
            let minutes = date.getMinutes()
            var data;
            minutes < 0 ? data = `0${minutes}` : data = minutes;
            //转换格式
            return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()} ${date.getHours()}:${data}`
        },

 
        handleSelect(key) {
            this.activeIndex = key;
        },
        closeDialog() {
            this.$emit("close");
        },
        changeType(e, index) {
            for (let i in this.typeData) {
                if (parseFloat(i) === index) {
                    this.typeData[i].show = true;
                    // checked = this.typeData[i].text;
                } else {
                    this.typeData[i].show = false;
                }
            }
            // this.checked = checked;
        },
        edit() {
            this.formData = this.$options.data.call(this).formData;
        },
        getDetail1(obj) {
            var data = {
                taskNumber: obj.taskNumber, //该数据的设备编号(必传)
                startDates: obj.startDates, //开始时间(必传) 精确到秒  一般传当前时间的前40分钟
                endDates: obj.endDates, //结束时间(必传）一般传当前时间的前40分钟

            }
            this.loading = true;
            getWs08HygsMonitordataByFids(data).then((res) => {
                if (res.errcode == 0) {
                    this.loading = false;

                    var data = res.data
                    this.chartsData = data
                    this.loadings = false
                    // this.$forceUpdate()

                }
            });
        },
        // 详情
        getDetail(obj) {
      
            getWs08HygsMonitordataByFid(obj).then((res) => {
                if (res.errcode == 0) {
                    var data = res.data.pageInfo.list
                    this.tableData = data
                    this.queryCriteriaData = res.data.pageInfo;
                }else {
                    this.loading=false;
                    this.$message.error(res.msg);
                }
            });
        },
        selectTime(e) {
            
            this.loadings = true
            if (e) {
                this.getList.startDates = e + " " + "00:00:00"; // 开始时间
                this.getList.endDates = e + " " + "23:59:59"; // 截至时间
            } else {
                this.getList.startDates = ""; // 开始时间
                this.getList.endDates = ""; // 截至时间
            }
            this.getList.timeDates = e

            this.getDetail(this.getList);
            this.getDetail1(this.getList);


        },


    },
};